home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
MacWorld: Complete Mac Interactive
/
Macworld Complete Mac Interactive CD)(1994).iso
/
The Best of BMUG
/
Utilities
/
Text and Speech
/
Alpha.5.76
/
Tcl
/
SystemCode
/
grep.tcl
< prev
next >
Wrap
Text File
|
1994-03-11
|
1KB
|
57 lines
#================================================================================
# 'greplist' and 'grepfset' are used for batch searching from the "find" dialog.
# Hence, you really shouldn't mess with them unless you know what you are doing.
#================================================================================
proc greplist {args} {
set num [expr [llength $args] - 2]
set exp [lindex $args $num]
set arglist [lindex $args [expr $num + 1]]
set owin 0
set cid [scancontext create]
set cmd [lrange $args 0 [expr $num - 1]]
eval scanmatch $cmd {$cid $exp {
if (!$owin) {
set owin 1
new
set w [lindex [winNames -f] 0]
}
insertText -w $w "File \"[file tail $f]\"; Line $matchInfo(linenum): $matchInfo(line)\r"}
}
foreach f $arglist {
set fid [open $f]
scanfile $cid $fid
close $fid
}
scancontext delete $cid
}
proc grepfset {args} {
global fileSets
set num [expr [llength $args] - 2]
set exp [lindex $args $num]
set fset [lindex $args [expr $num + 1]]
eval greplist [lrange $args 0 [expr $num-1]] {$exp $fileSets($fset)}
}
proc grep {exp args} {
set files {}
foreach arg $args {
append files " " [glob -t TEXT $arg]
}
set cid [scancontext create]
scanmatch $cid $exp {append lines "File \"[file tail $f]\"; Line $matchInfo(linenum): $matchInfo(line)\r"}
set lines ""
foreach f $files {
set fid [open $f]
scanfile $cid $fid
close $fid
}
scancontext delete $cid
return $lines
}